//
//  WXAddressDetailViewController.m
//  CarJX
//
//  Created by xcq on 14-10-17.
//  Copyright (c) 2014年 KK. All rights reserved.
//

#import "WXAddressDetailViewController.h"
#import "WXShowDetailTableViewCell.h"

@interface WXAddressDetailViewController ()

@end

@implementation WXAddressDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"路线详情";
    [self showNavBarWithRightTitle:nil andRightAction:nil andLeftAction:@selector(popToView) andCustom:NO];
}

- (void)popToView {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void) initTableView{
    if (_tableView ) {
        return;
    }
    _tableView = [[UITableView alloc] initWithFrame:self.view.frame];
    [_tableView registerNib:[UINib nibWithNibName:@"WXShowDetailTableViewCell" bundle:nil] forCellReuseIdentifier:@"showDetail"];
    
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [self.view addSubview: _tableView];
    
}

- (void) refreshTable{
    if (!_tableView) {
        return;
    }
    [_tableView reloadData];
}

- (void) setDateSource:(NSArray *)data   {
    if (data == nil) {
        return;
    }
    
    dateSource = [NSMutableArray arrayWithArray:data];
 // [dateSource insertObject:@"起点" atIndex:0];
  //  [dateSource insertObject:@"终点" atIndex: ([dateSource count])];
}

- (void)didReceiveMemoryWarning
{
    
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 77;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSLog(@"%ld" , [dateSource count]);
    return [dateSource count] > 0 ? [dateSource count] : 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    WXShowDetailTableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:@"showDetail"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    
    /*
     @property (nonatomic) int direction;
     ///路段入口信息
     @property (nonatomic, retain) BMKRouteNode* entrace;
     ///路段入口的指示信息
     @property (nonatomic, retain) NSString* entraceInstruction;
     ///路段出口信息
     @property (nonatomic, retain) BMKRouteNode* exit;
     ///路段出口指示信息
     @property (nonatomic, retain) NSString* exitInstruction;
     ///路段总体指示信息
     @property (nonatomic, retain) NSString* instruction;
     */
//    NSLog(@"%d",indexPath.row);
//     if (indexPath.row == 0) {
//         NSInteger row = indexPath.row ;
//         row ++;
//         BMKDrivingStep *step = [dateSource objectAtIndex:row];
//
//        NSString *str= step.instruction;
//        if ([str hasPrefix:@"起点"]) {
//            
//          NSRange range = [str rangeOfString:@"起点"];
//        str = [str substringFromIndex:range.length];
//            
//         [cell setDetailWithPhoto:step.instruction];
//
//        }
//    }else if(indexPath.row == ([dateSource count ] - 1 )  ){
//        [cell setDetailWithPhoto:@"终点"];
//    }else{
    
    
        BMKDrivingStep *step = [dateSource objectAtIndex:indexPath.row];

        [cell setDetailWithPhoto:step.instruction];
  //  }
 
    
    return cell;
}

@end
